<template>
  <div class='container'>
    <el-form ref="form" label-width="80px" :model="addParameter" :rules="addFromRules">
      <el-form-item label="所属学科">
        <el-select placeholder="请选择" v-model="addParameter.subjectID">
          <el-option v-for="item in subjectSimpleList" :label="item.label" :value="item.value" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目录名称" prop="directoryName">
        <el-input v-model="addParameter.directoryName" placeholder="请输入目录名称"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import * as Subject from '@/api/hmmm/subjects'
export default {
  data () {
    return {
      addParameter: {
        directoryName: '',
        subjectID: ''
      },
      subjectSimpleList: [], // 精简学科列表
      addFromRules: {
        directoryName: [
          { required: true, message: '请输入学科名称', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.getSubjectSimpleList()
  },
  updated () {
    this.toDirectory()
  },
  methods: {
    async getSubjectSimpleList () {
      const { data: res } = await Subject.simple()
      this.subjectSimpleList = res
      console.log(res)
    },
    toDirectory () {
      this.$emit('onAddParameter', this.addParameter)
    }
  }
}
</script>

<style scoped lang='less'></style>
